package com.zjuee.web.basic.message.service.impl;

import com.zjuee.service.basic.message.service.MessageService;
import com.zjuee.service.basic.message.vo.NotificationVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author wu liang
 * @since 1.0
 */
@Service
public class MessageServiceImpl implements MessageService {

//    @Resource
//    private PhoneMessageRemoteClient phoneClient;

    @Override
    public Boolean sendNotification(NotificationVo notificationVo) {
        String str = sendMessage(notificationVo.getMobile(), notificationVo.getContent(),
                notificationVo.getTemplateId(), notificationVo.getAccesskey(),
                notificationVo.getSecret(), notificationVo.getSign(), notificationVo.getSrcNo());
        return StringUtils.isNotBlank(str);
    }

    @Override
    public String sendMessage(String phone, String content, String templateId) {
        return sendMessage(phone, content, templateId, "1qMTs0wyIjjj20AS",
                "Q33XX5is44baW3kHyZwDpXv46TyR5dU1", "8914", "");
    }

    public String sendMessage(String phone, String content,
                              String templateId,String accesskey,
                              String secret, String sign,
                              String srcNo) {

//        String json = phoneClient.sendMessage(
//                accesskey, secret, sign,
//                templateId, phone, content, srcNo
//        );
//        //解析数据
//        if(StringUtils.isNotBlank(json)){
//            PhoneMessageDto phoneMessage = JSONObject.parseObject(json, PhoneMessageDto.class);
//            if(phoneMessage != null && StringUtils.isNotEmpty(phoneMessage.getCode())){
//                if("0".equals(phoneMessage.getCode())){
//                    return phoneMessage.getSmUuid();
//                }
//            }
//        }
        return "";
    }
}
